package LocalStorage

import (
	"KumquatDrivesServices/enums"
	"KumquatDrivesServices/utils"
	"os"
	"path/filepath"
)

func (Le LocalEngine) GetFile(filePath string, fileName string) ([]byte, error) {
	fileTypeEnums := enums.GetFileTypeBySuffix(filePath)
	suffix := filepath.Ext(fileName)
	fp := filepath.Join(filepath.Dir(filePath))
	if fileTypeEnums.Category == enums.VIDEO {
		switch suffix {
		case ".m3u8":
			m3u8Path := filepath.Join(fp, utils.GetBaseNameWithoutExt(filePath), "index.m3u8")
			return os.ReadFile(m3u8Path)
		case ".ts":
			tsPath := filepath.Join(fp, utils.GetBaseNameWithoutExt(filePath), fileName)
			return os.ReadFile(tsPath)
		}
	}

	return os.ReadFile(filePath)
}
